package ddemo.viewAndcontroller;

import ddemo.pojo.User;
import ddemo.service.UserService;
import ddemo.util.MD5Utils;

import java.util.Scanner;

public class loginView {
    public static void login(){
        Scanner sc=new Scanner(System.in);
        while (true) {
            String num="0";
            System.out.println("请输入账号");
            String username = sc.next();
            System.out.println("请输入密码");
            String password = sc.next();
            User user = UserService.login(username, MD5Utils.getPWD(password));
            if (user != null) {
                System.out.println("登入成功");
                System.out.println("————————————————");
                System.out.println("————————————————");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                menuView.chooseMnue(user);
            } else {
                System.out.println("账号密码错误,请选择重试或者注册账号");
                System.out.println("1.重试");
                System.out.println("2.注册");
                System.out.println("————————————————");
                System.out.println("————————————————");
                num=sc.next();

            }
            if("0".equals(num)){
                break;
            }
            else if("1".equals(num)){

            }
            else if("2".equals(num)){
                System.out.println(num);
                registerView.zhuce();
            }
            else{
                System.out.println(num);
                System.out.println("输出错误.请重试");
                System.out.println("————————————————");
                System.out.println("————————————————");
            }

        }



    }
}
